package com.example.administrator.testc.Viewpager;/**
 * Created by Administrator on 2016/5/7 0007.
 */

import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.view.ViewGroup;
import android.widget.TabWidget;

import com.example.administrator.testc.PagerAdapter.TestFragment;
import com.example.administrator.testc.R;

import java.util.ArrayList;
import java.util.List;

/**
 * >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>类描述
 * >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>属性描述
 * >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>方法描述
 */
public class TestMain extends AppCompatActivity {

    private ViewPager realtabcontent;
    private MyAdapter adapter;
    private List<Fragment> mDates = new ArrayList<Fragment>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        initPager();
        setContentView(R.layout.viewpager_layout);
        adapter = new MyAdapter(getSupportFragmentManager());
        realtabcontent = (ViewPager) findViewById(R.id.realtabcontent);
        realtabcontent.setOnPageChangeListener(new ViewPagerListener());
        realtabcontent.setAdapter(adapter);
    }

    private void initPager() {
        mDates.add(new TestFragment(Color.RED));
        mDates.add(new TestFragment(Color.GREEN));
        mDates.add(new TestFragment(Color.BLUE));
        mDates.add(new TestFragment(Color.YELLOW));
        mDates.add(new TestFragment(Color.WHITE));
    }

    class MyAdapter extends FragmentPagerAdapter {

        public MyAdapter(FragmentManager fm) {
            super(fm);
            // TODO Auto-generated constructor stub
        }

        @Override
        public Fragment getItem(int arg0) {
            return mDates.get(arg0);
        }

        @Override
        public int getCount() {
            return mDates.size();
        }

    }

    class ViewPagerListener implements ViewPager.OnPageChangeListener {
        @Override
        public void onPageScrollStateChanged(int arg0) {

        }

        @Override
        public void onPageScrolled(int arg0, float arg1, int arg2) {

        }

        @Override
        public void onPageSelected(int index) {

        }
    }
}
